﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UMLTouch.Core.UI;
using System.Windows;
using System.ComponentModel;

namespace UMLTouch.Core.Models
{
    public abstract class DiagramAnchor
    {

        public event EventHandler<DiagramAnchorMovedEventArgs> Anchor_Moved;

        public IDiagramItem Parent { get; private set; }

        Point _position;

        double _linkRadius = 100;

        public double LinkRadius
        {
            get { return _linkRadius; }
            set { _linkRadius = value; }
        }

        public Point Position
        {
            get { return _position; }
            protected set {
                if (_position == value)
                    return;
                Vector move = value - Position;
                _position = value;
                raiseAnchorMovedEvent(move);
            }
        }

        private void raiseAnchorMovedEvent(Vector move)
        {
            if (Anchor_Moved != null)
            {
                Anchor_Moved(this, new DiagramAnchorMovedEventArgs(this, move));
            }
        }

        public void Move(Vector move)
        {
            Position = Position + move;
        }

        public void MoveTo(Point p)
        {
            Position = p;
        }

        public DiagramAnchor(IDiagramItem parent,Point position)
        {
            Parent = parent;
            parent.Item_Moved += new EventHandler<DiagramItemMovedEventArgs>(parent_Item_Moved);
            _position = position;
        }

        void parent_Item_Moved(object sender, DiagramItemMovedEventArgs e)
        {
            Move(e.Move); 
        }

       
        

       
        
      

      

    }
}
